package com.gugee.ins.data.collector.blogger.listener;

import com.gugee.ins.data.collector.blogger.config.CollectorBloggerConfig;
import com.gugee.ins.data.collector.blogger.service.InsBloggerFollowingCollectService;
import com.gugee.ins.data.collector.blogger.service.InsFeedSvc;
import com.gugee.ins.data.common.consumer.AbstractGugeeConsumerHandler;
import com.gugee.ins.data.common.msg.InsBloggerMessage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.support.Acknowledgment;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:完成模拟推荐流
 * User: luolifeng
 * Date: 2020-12-24 11:13
 */

@Component
@Slf4j
public class InsFeedListener  {

    /**
     * 配置类
     */
    @Autowired
    CollectorBloggerConfig collectorBloggerConfig;

    /**
     * insFeedSvc
     */
    @Autowired
    InsFeedSvc insFeedSvc;
    /**
     * insBlogger服务
     */
    @Autowired
    InsBloggerFollowingCollectService insBloggerFollowingCollectService;

    FeedMsgHandler feedMsgHandler=new FeedMsgHandler();

    /**
     * 监听任务
     * @param messages
     * @param ack
     */
    @KafkaListener(id="${kafka.consumer.group.insBloggerFeed.id}",topics = {"${kafka.topics.insBloggerCollect.online}"},containerFactory = "factoryInsBloggerFeedAck")
    public void insFeedListener(List<InsBloggerMessage> messages, Acknowledgment ack) throws InterruptedException {
        Thread.sleep(collectorBloggerConfig.getInsFeedSpeedTimes()*1000L);
        feedMsgHandler.handle("InsFeedListener",messages,collectorBloggerConfig.getAcceptInsBloggerFeedMsgTimeMinRange(),ack);
    }

    class FeedMsgHandler extends AbstractGugeeConsumerHandler<InsBloggerMessage>{
        @Override
        public void dealMsg(List<InsBloggerMessage> messages) {
            //0全跳过、1跳过我的粉丝接口、2跳过我的关注列表接口、3都不跳过
            if(collectorBloggerConfig.getInsFeedJumpType()==0){
                return;
            }
            if(collectorBloggerConfig.getInsFeedJumpType()!=1){
                //我的粉丝列表
                insFeedSvc.followerFeedBloggerFromMsg(messages);
            }
            if(collectorBloggerConfig.getInsFeedJumpType()!=2) {
                // 我的关注列表
//                insBloggerFollowingCollectService.handleInsBloggerFollowingCollect(messages);
                insFeedSvc.followingFeedBloggerFromMsg(messages);
            }

        }
    }

}
